package com.maszy.commons.tools;
import java.security.MessageDigest;
public class MD5 {
	public static String encodePassword(String password,String algorithm) { 
		byte[] unencodedPassword = password.getBytes(); 

		MessageDigest md = null; 

		try { 
		md = MessageDigest.getInstance(algorithm); 
		} catch (Exception e) { 
		return password; 
		} 
		md.reset(); 
		md.update(unencodedPassword); 
		byte[] encodedPassword = md.digest(); 
		StringBuffer buf = new StringBuffer(); 

		for (int i = 0; i < encodedPassword.length; i++) { 
		if ((encodedPassword[i] & 0xff) < 0x10) { 
		buf.append("0"); 
		} 
		buf.append(Long.toString(encodedPassword[i] & 0xff, 16)); 
		} 

		return buf.toString(); 
	}
	public static void main(String[] args){
		String p=MD5.encodePassword("2816843", "MD5");
		System.out.println(p);
	}

}
